# Twitter and Identi.ca client written in Python
#

pkgname=turpial
pkgver=1.5.0
pkgrel=1
pkgdesc="Twitter and Identi.ca client written in Python"
url="http://turpial.org.ve/"
arch=('ppc')
license=('GPL3')
depends=('python2' 'python2-babel' 'python-notify' 'pywebkitgtk' \
				'pyxdg' 'pygobject' 'pygtk' 'gstreamer0.10-python' \
				'desktop-file-utils')
install=${pkgname}.install
source=("http://turpial.org.ve/files/sources/stable/${pkgname}-${pkgver}.tar.gz"
				turpial.desktop.patch
				turpial_main.py.patch
				turpial_ui_gtk_about.py.patch
				turpial)
md5sums=('e220f74db206203674e51cc56cf8b487'
				'3380817886bbf7677300978db8564f61'
				'18e97ceead82bbf372d925a00eaa5b17'
				'bfdf6e31758b5f198f39b36f0490cfa8'
				'bb7a267d8c4d14dc3b769c1cc7875fda')

build() {
	cd "${srcdir}/${pkgname}-${pkgver}"

	# Patches
	for patch in `ls ${srcdir}/*.patch`; do
		patch -Np0 -i ${patch}
	done
	find . -type f -name '*.py' | xargs \
		sed -i 's|python|python2\.7|'
	find turpial -type f -name '*.py' | xargs \
		sed -i 's|from turpial\.|from |g'
	# Avoid to center on screen, the window application
	sed -i 's|gtk.WIN_POS_CENTER|gtk.WIN_POS_CENTER_ON_PARENT|' \
		turpial/ui/gtk/main.py

	# i18n (.po -> .mo)
	/usr/bin/python2.7 setup.py compile_catalog --directory turpial/i18n

	# Bytecode Python
	/usr/bin/python2.7 -m compileall "${srcdir}/${pkgname}-${pkgver}"
	/usr/bin/python2.7 -O -m compileall "${srcdir}/${pkgname}-${pkgver}"

	# Clean .orig file
	find . -type f -name '*.orig' -exec rm -f "{}" \;
}

package() {
	# i18n
	mkdir -p "${pkgdir}/usr/share/locale"
	cd "${srcdir}/${pkgname}-${pkgver}/turpial/i18n"
	find . -type f -name '*.mo' \
		-exec install -D -m 644 "{}" "${pkgdir}/usr/share/locale/{}" \;

	cd "${srcdir}/${pkgname}-${pkgver}"

	# Documentation
	mkdir -p "${pkgdir}/usr/share/doc/${pkgname}"
	install -m 644 -t "${pkgdir}/usr/share/doc/${pkgname}" \
		AUTHORS COPYING TRANSLATORS README.rst 

	mkdir -p "${pkgdir}/usr/share/pixmaps"
	install -m 644 -t "${pkgdir}/usr/share/pixmaps" \
		turpial/data/pixmaps/turpial.png

	mkdir -p "${pkgdir}/usr/share/applications"
	install -m 644 -t "${pkgdir}/usr/share/applications" turpial.desktop

	#
	mkdir -p "${pkgdir}/usr/share/${pkgname}"
	find turpial -type d \
		\! -regex '.*i18n.*' \
		-exec mkdir -p "${pkgdir}/usr/share/{}" \;
	find turpial -type f ! -name '*.mo*' -and ! -name '*.po*' \
		-exec install -D -m 644 "{}" "${pkgdir}/usr/share/{}" \;

		#
		mkdir -p "${pkgdir}/usr/bin"
		install -m755 "${srcdir}/turpial" "${pkgdir}/usr/bin"
}
